//
//  PaymentView.m
//  SZBank
//
//  Created by rimi on 16/7/20.
//  Copyright © 2016年 LuoYao. All rights reserved.
//

#import "PaymentView.h"
@interface PaymentView()
{
    CGFloat frameWidth;/**  自身宽度 */
    CGFloat frameHeight;/**  自身高度 */
    NSMutableArray *sourceArray;
}
@property (nonatomic,strong) UIImageView *bgImageView;/**  背景图 */

@property (nonatomic,strong) UIImageView *titleView;/**  标题 */

@property (nonatomic,strong) UIScrollView *scrollView;/**  滚动视图 */

@property (nonatomic,strong) UIScrollView *imageScrollView;/**  图片滚动视图 */
@end
@implementation PaymentView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        frameWidth = self.frame.size.width;
        frameHeight = self.frame.size.height;
        [self addSubview:self.bgImageView];
        [self addSubview:self.titleView];
        [self imageScroll];
        sourceArray = [NSMutableArray array];
        /**  日常缴费数据请求 */
        [NetWorkingDataManager getProtocolTemplateUpdateWithProtocolid:@"402886c240623a74014065f955e50009" success:^(id sender) {
            NSInteger index = 0;
            for (NSDictionary *dic1 in sender) {
                if (index == 2) {
                    NSDictionary *dic2 = [dic1 objectForKey:@"protocolData"];
                    [sourceArray addObject:[dic2 objectForKey:@"移动缴费简介"][0]];
                    [sourceArray addObject:[dic2 objectForKey:@"电费简介"][0]];
                    [sourceArray addObject:[dic2 objectForKey:@"电信缴费简介"][0]];
                    [sourceArray addObject:[dic2 objectForKey:@"水费简介"][0]];
                    [sourceArray addObject:[dic2 objectForKey:@"联通缴费简介"][0]];
                    [sourceArray addObject:[dic2 objectForKey:@"煤气费简介"][0]];
                }
                index ++;
            }
            [self initUserInterface];
        } failure:nil];
    }
    return self;
}

- (void)initUserInterface{
    /**  滚动视图 */
    self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(frameWidth * 0.03, frameHeight * 0.047, frameWidth * 0.92, frameHeight * 0.4)];
    self.scrollView.contentSize = CGSizeMake(frameWidth * 0.9, frameHeight * 0.41);
    self.scrollView.showsVerticalScrollIndicator = NO;
    self.scrollView.backgroundColor = [UIColor whiteColor];
    for (int i = 0; i < sourceArray.count; i ++) {
        UIImageView *imageView;
        if (i == 3) {
            imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, i * 50 + 15, 20, 20)];
        }
        else{
            imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, i * 50 + 30, 20, 20)];
        }
        imageView.image = [LocalDataManager getImageWithSourceOfPath:@"日常缴费_01"];
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(40, i * 50, frameWidth * 0.88, frameHeight * 0.1)];
        label.font = [UIFont systemFontOfSize:24];
        label.text = sourceArray[i];
        label.numberOfLines = 0;
        [self.scrollView addSubview:imageView];
        [self.scrollView addSubview:label];
    }
    [self addSubview:self.scrollView];
}

- (void)imageScroll{
    NSArray *array = @[@"日常缴费_15",@"日常缴费_17",@"日常缴费_13",@"日常缴费_19",@"日常缴费__03",@"日常缴费_21"];
    for (int i = 0; i < array.count; i ++) {
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(i * frameWidth * 0.155, 0, frameWidth * 0.145, frameHeight * 0.2)];
        imageView.alpha = 0.7;
        imageView.image = [LocalDataManager getImageWithSourceOfPath:array[i]];
        [self.imageScrollView addSubview:imageView];
    }
    [self addSubview:self.imageScrollView];
}

- (UIImageView *)bgImageView{
    if (!_bgImageView) {
        _bgImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, frameWidth, frameHeight)];
        _bgImageView.image = [LocalDataManager getImageWithSourceOfPath:@"日常缴费_背景"];
    }
    return _bgImageView;
}

- (UIImageView *)titleView{
    if (!_titleView) {
        _titleView = [[UIImageView alloc] initWithFrame:CGRectMake(frameWidth * 0.4, frameHeight * 0.01, frameWidth * 0.12, frameHeight * 0.032)];
        _titleView.image = [LocalDataManager getImageWithSourceOfPath:@"日常缴费_03"];
    }
    return _titleView;
}

- (UIScrollView *)imageScrollView{
    if (!_imageScrollView) {
        _imageScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(frameWidth * 0.03, frameHeight * 0.7, frameWidth * 0.92, frameHeight * 0.2)];
        _imageScrollView.showsHorizontalScrollIndicator = NO;
        _imageScrollView.backgroundColor = [UIColor clearColor];
        _imageScrollView.contentSize = CGSizeMake(frameWidth * 0.925, frameHeight * 0.2);
    }
    return _imageScrollView;
}
@end
